package com.example.aop.pf;

import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

import com.example.aop.common.ForumService;
import com.example.aop.common.ForumServiceImpl;
import com.example.aop.common.UserService;
import com.example.aop.common.UserServiceImpl;

/**
 * 测试代理工厂类
 * 
 * @author Administrator
 *
 */
public class TestProxyFactory {

	public static void main(String[] args) {
		
//		UserService target = new UserServiceImpl();
//		// 2.AOP 代理工厂
//		ProxyFactory pf = new ProxyFactory(target);
//		// 3.装配Advice
//		pf.addAdvice(new SecurityInterceptor());
//		// pf.addAdvice(new LoggerBeforeAdvice());
//		pf.addAdvisor(new DefaultPointcutAdvisor(new LoggerBeforeAdvice()));
//		//// 4.获取代理对象
//		UserService proxy = (UserService) pf.getProxy();
//		// 5.调用业务
//		proxy.updateUser();
		
		test();
	}

	public static void test() {
		ForumService target = new ForumServiceImpl();
		// 2.AOP 代理工厂
		ProxyFactory proxyFactory = new ProxyFactory(target);
		// 3.装配Advice
		proxyFactory.addAdvice(new SecurityInterceptor());
		proxyFactory.addAdvice(new LoggerBeforeAdvice());
		//proxyFactory.addAdvisor(new DefaultPointcutAdvisor(new LoggerBeforeAdvice()));
		//// 4.获取代理对象
		ForumService proxy = (ForumService) proxyFactory.getProxy();
		proxy.removeForum(1);
		proxy.removeTopic(2);
	}
}
